package com.example.srb.common.exception;

import com.example.srb.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class UnifiedExceptionhandler {

    @ExceptionHandler(value = Exception.class)
    public Result handleException(Exception e){
      log.error(e.getMessage(),e);
      return Result.error();
    }

    @ExceptionHandler(value = BusinessException.class)
    public Result handleException(BusinessException e){
        log.error(e.getMessage(),e);
        return Result.error().message(e.getMessage()).code(e.getCode());
    }
}
